package com.ksana.util;

/**
 * @author Fall
 */
public class StringUtil {
    /**
     * 转换首字母大写
     */
    public static String upperCaseFirst(String name) {
        char[] arr = name.toCharArray();
        arr[0] = Character.toUpperCase(arr[0]);
        return new String(arr);
    }

    /**
     * 转换首字母小写
     */
    public static String lowerCaseFirst(String name) {
        char[] arr = name.toCharArray();
        arr[0] = Character.toLowerCase(arr[0]);
        return new String(arr);
    }

    /**
     * 文件只有位置的文件夹
     * @param path
     * @return
     */
    public static String getFolder(String path) {
        String[] str = path.split("\\.");
        String temp = "";
        for (int i = 0; i < str.length - 1; i++) {
            temp += str[i] + ".";
        }

        return temp.substring(0, temp.length() - 1);
    }

    /**
     * 得到一个字段的setter方法
     * @param name
     * @return
     */
    public static String getSetter(String name) {
        return "set" + StringUtil.upperCaseFirst(name);
    }

    /**
     * 判断字符串是否为空
     * @param str
     * @return
     */
    public static boolean isNotEmpty(String str) {
        return str == null || "".equals(str);
    }

    public static String replace(String str, String mode, String target) {
        return str.replace(mode, target);
    }
}
